<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义(手写)Promise</title>
    <script src="./Promise-JS/PromiseClass.js"></script>
</head>

<body>
    <!-- 
        自定义Promise对象
     -->
    <script>
        let promise = new Promise((resolve, reject) => {
            // reject('error')
            // resolve('ok')
            // throw 'error'
            // 模拟异步任务
            setTimeout(() => {
                resolve('OK')
                // reject('error')
            }, 1000)
        })
        console.log(promise)
        const res = promise.then(value => {
            console.log(value)
            return 'Hello'
            // throw 'error'
        }, reason => {
            // throw 'error'
            console.log(reason)
        })
        // promise.then(value => {
        //     alert(value)
        // }, reason => {
        //     console.log(reason)
        // })
        console.log(res)

        // 调用race方法
        let race1 = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('OK')
            }, 1000)
        })
        let race2 = Promise.reject('Reject')
        let race3 = Promise.resolve('Beauty')

        let raceResult = Promise.race([race1, race2, race3])
    </script>
</body>

</html>